<?php

use Biz\model\ShopFavorite as mShopFavorite;
use Biz\service\ShopGoodsOperator;
use Doraemon\tools\ActionLog as tActionLog;
use Doraemon\tools\HhzClient as tHhzClient;


class UnFavAction extends ActionPlugin
{

    const USER_LEVEL = self::LEVEL_REGISTER;

    const ACTION_TYPE = tActionLog::BIZ_GOODS_UNFAV;

    public function main()
    {
        $goods_id = $this->getRequest()->getPost('goods_id', 0);
		$obj_id = $this->getRequest()->getPost('obj_id', 0);
		$obj_type = $this->getRequest()->getPost('obj_type', mShopFavorite::TYPE_GOODS);

        if ($goods_id) {
        	$obj_id = $goods_id;
		}
		$app_source = 0;
		if (tHhzClient::getClientType() == tHhzClient::APPTYPE_PARAGRAPH_MINIPROGRAM) {
			$app_source = tHhzClient::APPTYPE_PARAGRAPH_MINIPROGRAM;
		} else if(tHhzClient::getClientType() == tHhzClient::APPTYPE_DESIGNER_FUNENG_MINIPROGRAM) {
            $app_source = tHhzClient::APPTYPE_DESIGNER_FUNENG_MINIPROGRAM;
        }

        ShopGoodsOperator::Unfavorite($this->uid, $obj_id, $obj_type, $app_source);

        if ($obj_type == mShopFavorite::TYPE_GOODS) {
            tActionLog::log($this->uid,[
                'uid' => $this->uid,
                'spu_id' => $obj_id,
            ], tActionLog::BIZ_GOODS_UNFAV);
        }
        if ($obj_type == mShopFavorite::TYPE_WIKI) {
            tActionLog::log($this->uid,[
                'uid' => $this->uid,
                'wiki_id' => $obj_id,
            ], tActionLog::BIZ_WIKI_UNFAV);
        }


        $this->setSuccess();

    }
}
